<!-- 年规 - 员工业绩 -添加员工业绩 -->
<template>
  <view>
    <view class="px-4 pb-25">
      <view class="flex items-center" @click="state.showTimePicker = true">
        <view class="flex-1 c-#333 text-32 font-600">成交日期</view>
        <view v-if="state.deal_time" class="flex-shrink-0 c-#333 w-533">{{ state.deal_time }}</view>
        <view v-else class="flex-shrink-0 c-#999 w-533">选择日期</view>
      </view>
      <view class="flex items-center mt-4">
        <view class="flex-1 c-#333 text-32 font-600">成交金额</view>
        <view class="input-style w-495 flex items-center">
          <u-input class="" v-model="state.money" placeholder="请输入您的金额" :placeholder-style="placeholderStyle"
            :custom-style="customStyle" type="digit" />
        </view>
        <view class="c-#333 text-28 ml-3">{{ currency?.value == 1 ? '$' : '¥' }}</view>
      </view>
    </view>
    <view class="bottom-wrap-16 bg-white border-top px-4" @click="onSubmit">
      <view class="button-save">保存</view>
    </view>
    <u-picker v-model="state.showTimePicker" mode="time" :params="timeParams" confirm-color="#F4AF22"
      @confirm="onTimeConfirm" />
  </view>
</template>

<script setup>
import { dateFormat } from '@/common/util/date'
import { showToast } from '@/common/util/uni'
import { refreshPrePage } from '@/common/util/util'
import { postEmployeeAdd,postEditRecord } from '@/common/http/module/plan'

import { usePlanStore } from '@/store/plan'

const planStore = usePlanStore()

const state = reactive({
  employee_id: '',
  deal_time: '',
  money: '',
  showTimePicker: false,
  log_id:''
})
const placeholderStyle = {
  "color": '#999'
}
const customStyle = {
  "color": '#333'
}

const timeParams = { year: true, month: true, day: true, hour: true, minute: true, seconds: true, timestamp: true }
const currency = computed(() => planStore.currency)

function onTimeConfirm(e) {
  console.log('onTimeConfirm', e);
  const { timestamp } = e
  state.deal_time = dateFormat(timestamp)
}

function onSubmit() {
  const params = {
    employee_id: state.employee_id,
    money: state.money,
    deal_time: state.deal_time,
    log_id:state.log_id
  }
  if(state.type == 'add'){
    postEmployeeAdd(params).then(() => {
    showToast('保存成功')
    refreshPrePage('refresh')
    setTimeout(() => {
      uni.navigateBack()
    }, 600);
  })
  }else{
    postEditRecord(params).then(() => {
    showToast('编辑成功')
    refreshPrePage('refresh')
    setTimeout(() => {
      uni.navigateBack()
    }, 600);
  })
  }
 
}

onLoad(options => {
  state.employee_id = options.employeeId
  state.money = options.money
  state.deal_time = options.deal_time
  state.type = options.type
  state.log_id = options.log_id
})
</script>

<style lang="scss" scoped>
.input-style {
  padding: 14rpx 50rpx;
  height: 68rpx;
  border-radius: 12rpx;
  background-color: #F6F6F6;
  color: #999;
  font-size: 28rpx;
}

.button-save {
  height: 68rpx;
  border-radius: 5px;
  background-color: #F4AF22;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-size: 28rpx;
}

.border-top {
  border-top: 2rpx solid #eee;
}
</style>
